package com.modbus.tcp.controller;

import java.util.List;

import com.modbus.tcp.utils.ApiReturnObject;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.modbus.tcp.domain.Ballvalvedata;
import com.modbus.tcp.service.IBallvalvedataService;


/**
 * 球阀modbus数据 信息操作处理
 *
 * @author d
 * @date 2024-01-11
 */
@RestController
@RequestMapping("/ballvalvedata")
public class BallvalvedataController {

    @Autowired
    private IBallvalvedataService ballvalvedataService;

//    /**
//     * 查询球阀modbus数据列表
//     */
//    @GetMapping("/list")
//    public ApiReturnObject list(Ballvalvedata ballvalvedata,Integer pageNum,Integer pageSize) {
//        if(pageNum != null && pageSize !=null ){
//            PageHelper.startPage(pageNum,pageSize);
//        }
//        List<Ballvalvedata> list = ballvalvedataService.selectBallvalvedataList(ballvalvedata);
//        PageInfo pageInfo = new PageInfo<>(list);
//        return new ApiReturnObject("200","查询成功",pageInfo);
//    }

    /**
     * 查询球阀modbus数据列表
     */
    @GetMapping("/list")
    public ApiReturnObject list(Ballvalvedata ballvalvedata) {
//        Ballvalvedata ballvalvedata= new Ballvalvedata();
//        ballvalvedata.setModbusid(modbusid);
        List<Ballvalvedata> list = ballvalvedataService.selectBallvalvedataList(ballvalvedata);

        return new ApiReturnObject("200","查询成功",list);
    }

    @GetMapping("/SensordataList")
    public ApiReturnObject list(Integer id) {

        List<Ballvalvedata> list = ballvalvedataService.selectSensordataList(id);

        return new ApiReturnObject("200","查询成功",list);
    }

    /**
     * 新增保存球阀modbus数据
     */

    @PostMapping("/add")
    public ApiReturnObject addSave(@RequestBody Ballvalvedata ballvalvedata) {
        ballvalvedataService.insertBallvalvedata(ballvalvedata);
        return new ApiReturnObject("200","添加成功","");
    }


    /**
    * 详情球阀modbus数据
    */
    @GetMapping("/selectOne")
    public ApiReturnObject selectOne(Integer id){
        Ballvalvedata result = ballvalvedataService.selectBallvalvedataById(id);
        return new ApiReturnObject("200","查询成功",result);
    }

    /**
     * 修改保存球阀modbus数据
     */

    @PostMapping("/update")
    public ApiReturnObject editSave(@RequestBody Ballvalvedata ballvalvedata) {
        ballvalvedataService.updateBallvalvedata(ballvalvedata);
        return new ApiReturnObject("200","修改成功","");
    }

    /**
     * 删除球阀modbus数据
     */

    @PostMapping("/del")
    public ApiReturnObject remove(String ids) {
        ballvalvedataService.deleteBallvalvedataByIds(ids);
        return new ApiReturnObject("200","删除成功","");
    }

    @PostMapping("/addList")
    public ApiReturnObject addSaveList(@RequestBody List<Ballvalvedata> list) {
        ballvalvedataService.insertBallvalvedataList(list);
        return new ApiReturnObject("200","添加成功","");
    }

}